<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div>
            <span>全选:</span>
            <input type="checkbox" v-model="fn" />
            <button @click="fn1">反选</button>
            <ul>
                <li v-for="item in arr">
                    <input type="checkbox" v-model="item.checked" />
                    <span>{{item.name}}</span>
                </li>
            </ul>
        </div>
    </div>
    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                arr: [
                    {
                        name: "猪八戒",
                        checked: false,
                    },
                    {
                        name: "孙悟空",
                        checked: false,
                    },
                    {
                        name: "唐僧",
                        checked: false,
                    },
                    {
                        name: "白龙马",
                        checked: false,
                    },
                ],
            },
            // 计算属性
            computed: {
                fn:{
                    get() {  
                        // every的返回值是布尔值  每一项都满足就返回true  只要有一项不满足就是false
                        return this.arr.every(item=>item.checked) 
                    },
                    set(newVal) { 
                        return this.arr.forEach(item => {
                            item.checked=newVal
                        });
                     }
                }
            },
            methods:{
                fn1() {
                    this.fn=!this.fn
                }
            }
        })
    </script>


</body>

</html>